package DBLayer;

import java.sql.*;

import DBLayer.DBConnection1;
import DBLayer.IFDBProductLine;
import ModelLayer.ProductLine;


public class DBProductLine implements IFDBProductLine{
	private Connection con;
	
	public DBProductLine()
	{
		 con = DBConnection1.getInstance().getDBcon();
	}
	
	public int insertProductLine(ProductLine productLine) throws Exception
	{
		String query = "INSERT INTO ProductLine(prodId, quantity, price, orderId) VALUES('" +
				productLine.getProduct().getId()+"','"+
				productLine.getQuantity() +"','"+
				productLine.getSubPrice()+
				productLine.getOrder().getOrderId() + "')";
		
		int rc = -1;
		System.out.println("insert: " + query);
		try {
			Statement stmt = con.createStatement();
			stmt.setQueryTimeout(5);
			rc = stmt.executeUpdate(query);
			stmt.close();
		} catch (SQLException ex) {
			System.out.println("Employee is not inserted");
	        throw new Exception ("Employee is not inserted correct");
		}
		
		return rc;
	}
}
